package st.business.tepth.business.user.busnumber.workholder.repair.finish;

import st.business.tepth.base.OnDataConvertListener;

/**
 * Author: shadow
 * Email:  1025431817@qq.com
 * Time:   2019-03-26 11:11
 */

public class RepairCompletePresenter extends RepairCompleteContract.Presenter {
    private final RepairCompleteContract.View mView;
    private final RepairCompleteContract.Model mModel;

    public RepairCompletePresenter(RepairCompleteContract.View view) {
        mView = view;
        mModel = new RepairCompleteModel();
    }

    @Override
    void complete(String token, int id,
                  String repairTaskIds,
                  String reason, final int status) {
        addDisposable(mModel.complete(token, id, repairTaskIds, reason, status,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String workInfoBean) {
                        if (mView != null) {
                            if (status == 0) {
                                mView.completePass();
                            } else {
                                mView.completeNotPass();
                            }
                        }
                    }

                    @Override
                    public void error(int code, String msg) {
                        if (mView != null) {
                            mView.showError(msg);
                        }
                    }
                }));
    }

    @Override
    void cancelFinishWork(String token, int repairId) {
        addDisposable(mModel.cancelFinishWork(token, repairId,
                new OnDataConvertListener<String>() {
                    @Override
                    public void convert(String s) {
                        mView.cancelWorkSucceed();
                    }

                    @Override
                    public void error(int code, String msg) {
                        mView.showError(msg);
                    }
                }));
    }
}
